declare namespace msds = "http://matsadaml.org/msds/v1.0"; 
declare variable $ProductGroups as xs:string external;

document
{
    processing-instruction {"xml-stylesheet"} {"type='text/xsl' href='System/Transformations/index_summary.xsl'"},
    element index {
    
        element substanceDBs {
    
            for $db in doc("../../Substances/SubstanceDBs.xml")/msds:substanceDBs/msds:db
            order by $db/@key
            return
                element db {
                    attribute key {$db/@key},
                        element name {$db/msds:name},
                        element description {$db/msds:description},
                        element location {$db/msds:location}
                }
        },
            
        element productGroups {
            for $group in $ProductGroups
            return
                <group>{normalize-space($group)}</group>
        }
    }
}
